<?php
/**
 * Created by PhpStorm.
 * User: MADAO
 * Date: 2019/9/27
 * Time: 22:59
 */
declare (strict_types=1);

namespace App\Traits;

use App\Model\User;
use Hyperf\Utils\ApplicationContext;
use Hyperf\HttpServer\Contract\RequestInterface;

trait UserTrait
{
    public function authUser()
    {
        $container = ApplicationContext::getContainer();
        $request = $container->get(RequestInterface::class);
        $token = $request->header('Authorization');
        $token = str_replace('Bearer ', '', $token);
        return User::query()->where(['token' => $token])->first();
    }
}
